<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>起点-视频播放平台</title>
    <link href="css/index.css" rel="stylesheet"/>
    <script src="js/jquery-3.4.1.min.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <script src="js/check-login.js"></script>
    <script>
        $(document).ready(function(){
            checkLogin(function(res){// 这里的res就是校验的结果
                if(res.code==200){
                    $(".login-div").html("欢迎您["+res.data.username+"]! [<a href='javascript:doExit()'>退出</a>]");
                }else{  
                    $(".login-div").html("[<a href='reg.html'>注册</a>][<a href='login.html'>登陆</a>]");
                }
            });
        });

        function doExit(){
            $.ajax({
                type:"get",
                url:"http://localhost:8080/study/userlogin",
                data:{op:"exit",token:$.cookie('token')},
                success:function(){
                    location.href="index.html";
                }
            })
        }
    </script>
</head>
<body>
    <div class="box">
        <div class="top">
            <div class="hengfu">

            </div>
            <div class="login-div">
                [<a href="reg.html">注册</a>]
                [<a href="login.html">登陆</a>]
            </div>
        </div>
        <div class="banner">
            <div class="lunbo"></div>
            <div class="zixun"></div>
        </div>
        <div class="tag">
            
        </div>
        <div class="video-list"></div>
        <div class="link"></div>
        <div class="footer"></div>
    </div>
    <script>
        // 查询横幅
        $.get("http://localhost:8080/study/content?op=queryByCatId&catId=6",function(res){
            if(res.code==200 && res.data.length > 0){
                // 取出第一个
                $(".hengfu").append("<a href='"+res.data[0].link1+"'><img height='50' width='998' src='"+res.data[0].pic1+"'/></a>");
            }
        });
        // 加载轮播图
        $.get("http://localhost:8080/study/content?op=queryByCatId&catId=2",function(res){
            if(res.code==200 && res.data.length > 0){
                let width = (996 / res.data.length)-8;
                $.each(res.data,function(index,item){
                    $(".lunbo").append("<a href='"+item.link1+"'><img height='150' width='"+width+"' src='"+item.pic1+"'/></a>");
                })
            }
        });
        // 新闻
        $.get("http://localhost:8080/study/content?op=queryByCatId&catId=5",function(res){
            if(res.code==200 && res.data.length > 0){
                let width = (996 / res.data.length)-8;
                let ul = $("<ul>");
                    $(".zixun").append(ul);
                $.each(res.data,function(index,item){
                    ul.append("<li align='top'><a href='"+item.link1+"'>"+item.text1+"</a></li>");
                })
            }
        });
    </script>
</body>
</html>